package com.becca.cake.controller.order;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.mail.internet.MimeMessage;
import javax.print.DocFlavor;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import sun.awt.AppContext;

import com.becca.cake.core.common.BaseAction;
import com.becca.cake.core.common.PagingBean;
import com.becca.cake.core.constant.CommonConstants;
import com.becca.cake.core.exception.CommonExceptionHandle;
import com.becca.cake.core.print.PrintServiceName;
import com.becca.cake.model.logistic.LogisticStatusModel;
import com.becca.cake.model.order.GoodOrderModel;
import com.becca.cake.model.order.OrderDetailsModel;
import com.becca.cake.model.order.OrderModel;
import com.becca.cake.model.order.OrderRefundsModel;
import com.becca.cake.model.order.OrdersTodayModel;
import com.becca.cake.service.goods.IGoodsService;
import com.becca.cake.service.orders.IOrderService;
import com.becca.cake.util.DateUtils;
import com.becca.cake.util.JsonUtil;

/**
 * 订单管理Controller
 * @copyright  尊星(上海)信息科技有限公司
 * @author yellow
 * @date 2016年5月18日 下午3:27:15
 */
@Controller
@RequestMapping("/orderManager")
public class OrderAction extends BaseAction {
    private static final Logger logger = LoggerFactory.getLogger(OrderAction.class);

    @Autowired
    private IOrderService       iOrderService;
    @Autowired
    private IGoodsService       iGoodsService;
    @Autowired
    private JavaMailSender      javaMailSender;

    //配送坐标数据
    @PostConstruct
    public void init() {
        this.iOrderService.initBaiduRangeInfo();
    }

    /**
     * 查询订单信息
     * @param orderModel
     * @return
     */
    @RequestMapping(value = "/selectOrders", method = RequestMethod.POST)
    @ResponseBody
    public String selectOrders(@ModelAttribute OrderModel orderModel) {
        //step1:获取请求参数
        PagingBean page = getInitPagingSortBean();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("orderModel", orderModel);
        map.put("pagingBean", page);
        try {
            //step2:查询订单数据
            List<OrderModel> list = this.iOrderService.selectOrders(map);
            Long count = this.iOrderService.selectOrdersCount(map);
            //step3:返回订单数据
            return JsonUtil.writeObjectPageJSON(list, count);
        } catch (Exception e) {
            return JsonUtil.returnJsonUnSuccess(CommonExceptionHandle.handleException(e));
        }
    }

    /**
    * 修改订单数据
    * @param orderModel
    * @return
    */
    @RequestMapping(value = "/updateOrder", method = RequestMethod.POST)
    @ResponseBody
    public String updateOrder(OrderModel orderModel) {
        try {
            orderModel.setUpdatedName(this.getUserSeesion().getTrueName());
            this.iOrderService.updateOrder(orderModel);
            return JsonUtil.returnJsonSuccess("修改订单信息成功!");
        } catch (Exception e) {
            return JsonUtil.returnJsonUnSuccess(CommonExceptionHandle.handleException(e));
        }
    }

    /**
     * 根据orderId获取订单对象
     * @param orderId
     * @return
     */
    @RequestMapping(value = "/findOrderById", method = RequestMethod.POST)
    @ResponseBody
    public String findOrderById(@RequestParam(value = "orderId", required = false) Integer orderId) {
        try {
            OrderModel orderModel = this.iOrderService.findOrderById(orderId);
            return JsonUtil.writeObjectFormJSON(orderModel);
        } catch (Exception e) {
            logger.error("获取订单对象失败!");
            return JsonUtil.returnJsonUnSuccess("获取订单对象失败!");
        }
    }

    /**
     * 根据订单编号查询订单详情
     * @param orderId
     * @return
     */
    @RequestMapping(value = "/queryOrderDetail", method = RequestMethod.POST)
    @ResponseBody
    public String queryOrderDetail(@RequestParam(value = "orderId", required = false) Integer orderId) {
        try {
            List<OrderDetailsModel> list = this.iOrderService.selectDetailsByOrderId(orderId);
            return JsonUtil.writeObjectNoPageJSON(list);
        } catch (Exception e) {
            return JsonUtil.returnJsonUnSuccess(CommonExceptionHandle.handleException(e));
        }
    }

    /**
     * 单个/批量修改订单状态
     * @return
     */
    @RequestMapping(value = "/updateOrderStatus", method = RequestMethod.POST)
    @ResponseBody
    public String updateOrderStatus(@RequestParam(value = "orderIds", required = false) String orderIds,
                                    @RequestParam(value = "orderStatus", required = false) String orderStatus,
                                    @RequestParam(value = "statusName", required = false) String statusName,
                                    @RequestParam(value = "cancelReason", required = false) String cancelReason,
                                    @RequestParam(value = "beforeRefundOrderStatus", required = false) String beforeRefundOrderStatus,
                                    @RequestParam(value = "refundsPrice", required = false) Double refundsPrice) {
        //step1:封装请求参数
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("orderIds", orderIds);
        paramMap.put("orderStatus", orderStatus);
        paramMap.put("statusName", statusName);
        paramMap.put("cancelReason", cancelReason);
        paramMap.put("userName", this.getUserSeesion().getTrueName());
        paramMap.put("refundsPrice", refundsPrice);
        paramMap.put("beforeRefundOrderStatus", beforeRefundOrderStatus);
        try {
            //step2:修改订单状态
            this.iOrderService.updateOrderStatus(paramMap);
            return JsonUtil.returnJsonSuccess("操作订单状态成功!");
        } catch (Exception e) {
            return JsonUtil.returnJsonUnSuccess(CommonExceptionHandle.handleException(e));
        }
    }

    /**
     * 修改物流单号
     * @return
     */
    @RequestMapping(value = "/updateOrderLogisticNo", method = RequestMethod.POST)
    @ResponseBody
    public String updateOrderLogisticNo(@RequestParam(value = "orderId", required = false) Integer orderId,
                                        @RequestParam(value = "logisticNo", required = false) String logisticNo) {
        //step1:封装请求参数
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("orderId", orderId);
        paramMap.put("logisticNo", logisticNo);
        paramMap.put("userName", this.getUserSeesion().getTrueName());
        try {
            //step2:修改物流单号
            this.iOrderService.updateOrderLogisticNo(paramMap);
            return JsonUtil.returnJsonSuccess("修改物流单号成功!");
        } catch (Exception e) {
            return JsonUtil.returnJsonUnSuccess(CommonExceptionHandle.handleException(e));
        }
    }

    /**
     * 订单打印
     * @param orderId
     * @param model
     * @return
     */
    @RequestMapping(value = "/printOrder", method = RequestMethod.GET)
    public String printOrder(@RequestParam(value = "orderId", required = false) Integer orderId,
                             Model model) {
        try {
            //step1:订单信息
            OrderModel orderModel = this.iOrderService.findOrderById(orderId);
            //step2:订单详情
            List<OrderDetailsModel> list = this.iOrderService.selectDetailsByOrderId(orderId);
            model.addAttribute("orderModel", orderModel);
            model.addAttribute("orderList", list);
        } catch (Exception e) {
            return JsonUtil.returnJsonUnSuccess(CommonExceptionHandle.handleException(e));
        }
        return "print/printOrder";
    }

    /**
     * 查询物流状态列表
     * @param logisticStatusModel
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/queryLogisticStatus", method = RequestMethod.POST)
    public String queryLogisticStatus(@RequestParam(value = "orderId", required = false) Integer orderId) {
        //step1:获取请求参数
        PagingBean page = getInitPagingBean();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("orderId", orderId);
        map.put("pagingBean", page);
        try {
            //step2:查询订单数据
            List<LogisticStatusModel> list = this.iOrderService.queryLogisticStatus(map);
            Long count = this.iOrderService.queryLogisticStatusCount(map);
            //step3:返回订单数据
            return JsonUtil.writeObjectPageJSON(list, count);
        } catch (Exception e) {
            return JsonUtil.returnJsonUnSuccess(CommonExceptionHandle.handleException(e));
        }
    }

    /**
     * @author 获取所有的打印机名称信息
     * @author hejinguo
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getAllPrintService", method = RequestMethod.POST)
    public String getAllPrintService() {
        AppContext.getAppContext().put(PrintServiceLookup.class.getDeclaredClasses()[0], null);
        // 查找所有的可用的打印服务
        PrintService printService[] = PrintServiceLookup.lookupPrintServices(
            DocFlavor.INPUT_STREAM.AUTOSENSE, null);
        List<PrintServiceName> list = new ArrayList<PrintServiceName>();
        PrintServiceName printServiceName = null;
        for (PrintService printSer : printService) {
            printServiceName = new PrintServiceName();
            printServiceName.setPrintName(printSer.getName());
            list.add(printServiceName);
        }
        String resultStr = JsonUtil.writeObjectNoPageJSON(list);
        logger.info("获取打印机信息!" + resultStr);
        return resultStr;
    }

    /**
     * 热敏订单打印
     * @param orderId
     * @param model
     * @return
     */
    @RequestMapping(value = "/printThermalOrder", method = RequestMethod.GET)
    public String printThermalOrder(@RequestParam(value = "orderId", required = false) String orderId,
                                    Model model) {
        try {
            //step1:封装请求参数
            Map<String, Object> paramMap = new HashMap<String, Object>();
            paramMap.put("orderId", orderId);
            //step2:生成订单静态页面信息
            List<String> orderHtmlUrlList = this.iOrderService.printThermalOrder(
                getFreeMarketFoderPath(), paramMap);
            model.addAttribute("orderHtmlUrlList", orderHtmlUrlList);
        } catch (Exception e) {
            return JsonUtil.returnJsonUnSuccess(CommonExceptionHandle.handleException(e));
        }
        return "print/printThemeOrder";
    }

    /**
     * 交接单打印
     * @param orderIds
     * @param model
     * @return
     */
    @RequestMapping(value = "/printHandOverOrder", method = RequestMethod.GET)
    public String printHandOverOrder(@RequestParam(value = "orderIds", required = false) String orderIds,
                                     Model model) {
        //step1:封装请求参数
        try {
            //step2:获取订单列表对象
            List<OrderModel> orderList = this.iOrderService.selectHandOverOrdersComfirmed(orderIds);
            model.addAttribute("orderList", orderList);
            model.addAttribute("userName", this.getUserSeesion().getTrueName());
            String nowDate = DateUtils.DateToString(new Date(),
                DateUtils.FORMAT_yyyy_nian_M_yue_m_ri);
            model.addAttribute("nowDate", nowDate);
        } catch (Exception e) {
            return JsonUtil.returnJsonUnSuccess(CommonExceptionHandle.handleException(e));
        }
        return "print/deliveryReceitp";
    }

    /**
     * 批量导出订单数据
     * @param jsonList
     * @return
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @RequestMapping(value = "/exportOrdersToExcel", method = RequestMethod.GET)
    public void exportOrdersToExcel(HttpServletRequest request,
                                    HttpServletResponse response,
                                    @RequestParam(value = "orderIds", required = false) String orderIds) {
        List list = this.iOrderService.selectOrderExcelModel(orderIds);
        try {
            this.iOrderService.exportOrdersToExcel(request, response, list);
        } catch (Exception e) {
            logger.error("订单数据导出excel失败!");
        }
    }

    /**
     * 填写配送人员信息
     * @return
     */
    @RequestMapping(value = "/updateOrderDeliveryInfo", method = RequestMethod.POST)
    @ResponseBody
    public String updateOrderDeliveryInfo(@RequestParam(value = "orderId", required = false) Integer orderId,
                                          @RequestParam(value = "deliveryMan", required = false) String deliveryMan,
                                          @RequestParam(value = "deliveryMobileNo", required = false) String deliveryMobileNo) {
        //step1:封装请求参数
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("orderId", orderId);
        paramMap.put("deliveryMan", deliveryMan);
        paramMap.put("deliveryMobileNo", deliveryMobileNo);
        paramMap.put("userName", this.getUserSeesion().getTrueName());
        try {
            //step1:填写信息
            this.iOrderService.updateOrderDeliveryInfo(paramMap);
            return JsonUtil.returnJsonSuccess("添加物流信息成功!");
        } catch (Exception e) {
            return JsonUtil.returnJsonUnSuccess(CommonExceptionHandle.handleException(e));
        }
    }

    /**
     * 修改物流信息
     * @return
     */
    @RequestMapping(value = "/updateOrderLogisticsMessage", method = RequestMethod.POST)
    @ResponseBody
    public String updateOrderLogisticsMessage(@RequestParam(value = "logisticId", required = false) Integer logisticId,
                                              @RequestParam(value = "logisticMessage", required = false) String logisticMessage) {
        //step1:封装请求参数
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("logisticId", logisticId);
        paramMap.put("logisticMessage", logisticMessage);
        paramMap.put("userName", this.getUserSeesion().getTrueName());
        try {
            //step1:修改物流信息
            this.iOrderService.updateOrderLogisticsMessage(paramMap);
            return JsonUtil.returnJsonSuccess("修改物流信息成功!");
        } catch (Exception e) {
            return JsonUtil.returnJsonUnSuccess(CommonExceptionHandle.handleException(e));
        }
    }

    /**
     * 拒收订单处理
     * @param orderId
     * @param orderStatus
     * @param payType
     * @param refundsReason
     * @return
     */
    @RequestMapping(value = "/refuseReceive", method = RequestMethod.POST)
    @ResponseBody
    public String refuseReceive(@RequestParam(value = "orderId", required = false) String orderId,
                                @RequestParam(value = "orderStatus", required = false) String orderStatus,
                                @RequestParam(value = "orderType", required = false) String orderType,
                                @RequestParam(value = "refundsReason", required = false) String refundsReason,
                                @RequestParam(value = "beforeRefundOrderStatus", required = false) Byte beforeRefundOrderStatus,
                                @RequestParam(value = "refundsPrice", required = false) Double refundsPrice) {
        //step1:封装请求参数
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("orderId", orderId);
        paramMap.put("orderStatus", orderStatus);
        paramMap.put("refundsReason", refundsReason);
        paramMap.put("orderType", orderType);
        paramMap.put("beforeRefundOrderStatus", beforeRefundOrderStatus);
        paramMap.put("refundsPrice", refundsPrice);
        paramMap.put("userName", this.getUserSeesion().getTrueName());
        try {
            //step2:修改订单状态
            this.iOrderService.updRefuseReceiveOrder(paramMap);
            return JsonUtil.returnJsonSuccess("操作订单状态成功!");
        } catch (Exception e) {
            return JsonUtil.returnJsonUnSuccess(CommonExceptionHandle.handleException(e));
        }
    }

    /**
     * 配送单打印
     * @param orderIds
     * @param model
     * @return
     */
    @RequestMapping(value = "/printDeliveryOrder", method = RequestMethod.GET)
    public String printDeliveryOrder(@RequestParam(value = "orderIds", required = false) String orderIds,
                                     Model model) {
        //step1:封装请求参数
        try {
            //step2:获取订单列表对象
            List<OrderModel> orderList = this.iOrderService.selectHandOverOrders(orderIds);
            model.addAttribute("orderList", orderList);
            //model.addAttribute("userName", this.getUserSeesion().getTrueName());
        } catch (Exception e) {
            return JsonUtil.returnJsonUnSuccess(CommonExceptionHandle.handleException(e));
        }
        return "print/deliveryOrder";
    }

    /**
     * 提交生成订单
     * @param jsonMessage
     * @return
     */
    @RequestMapping(value = { "/saveOrder" }, method = RequestMethod.POST)
    @ResponseBody
    public String saveOrder(@ModelAttribute GoodOrderModel goodOrderModel,
                            @RequestParam(value = "jsonList", required = false) String jsonList) {
        try {
            this.iOrderService.saveOrder(goodOrderModel, jsonList, this.getUserSeesion()
                .getTrueName());
            return JsonUtil.returnJsonSuccess("操作订单状态成功!");
        } catch (Exception e) {
            return JsonUtil.returnJsonUnSuccess(CommonExceptionHandle.handleException(e));
        }
    }

    /**
     * @param goodOrderModel
     * @return
     */
    @RequestMapping(value = { "/selectGoodsPrices" }, method = RequestMethod.POST)
    @ResponseBody
    public String selectGoodsPrices(@ModelAttribute GoodOrderModel goodOrderModel) {
        PagingBean page = getInitPagingSortBean();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("pagingBean", page);
        try {
            List<GoodOrderModel> list = this.iOrderService.selectGoodsPrize(map);
            Long count = this.iOrderService.selectGoodsPrizeCount(map);
            return JsonUtil.writeObjectPageJSON(list, count);
        } catch (Exception e) {
            return JsonUtil.returnJsonUnSuccess(CommonExceptionHandle.handleException(e));
        }
    }

    /**
     * @param orderRefundsModel
     * @return
     */
    @RequestMapping(value = { "/selectOrderRefunds" }, method = RequestMethod.POST)
    @ResponseBody
    public String selectOrderRefunds(@ModelAttribute OrderRefundsModel orderRefundsModel) {
        PagingBean page = getInitPagingSortBean();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("pagingBean", page);
        map.put("orderRefundsModel", orderRefundsModel);
        try {
            List<OrderRefundsModel> list = this.iOrderService.selectOrderRefundsList(map);
            Long count = this.iOrderService.selectOrderRefundsCount(map);
            return JsonUtil.writeObjectPageJSON(list, count);
        } catch (Exception e) {
            return JsonUtil.returnJsonUnSuccess(CommonExceptionHandle.handleException(e));
        }
    }

    /**
     * 单个/批量修改订单退款状态
     * @return
     */
    @RequestMapping(value = "/updateOrderRefundsStatus", method = RequestMethod.POST)
    @ResponseBody
    public String updateOrderRefundsStatus(@RequestParam(value = "orderIds", required = false) String orderIds,
                                           @RequestParam(value = "refundsStatus", required = false) String refundsStatus,
                                           @RequestParam(value = "refusedReason", required = false) String refusedReason,
                                           @RequestParam(value = "ids", required = false) String ids,
                                           @RequestParam(value = "orderStatusArr", required = false) String orderStatusArr,
                                           @RequestParam(value = "refundsPrice", required = false) String refundsPrice,
                                           @RequestParam(value = "statusName", required = false) String statusName) {
        //step1:封装请求参数
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("ids", ids);
        paramMap.put("orderIds", orderIds);
        paramMap.put("userName", this.getUserSeesion().getTrueName());
        paramMap.put("refundsStatus", refundsStatus);
        paramMap.put("refusedReason", refusedReason);
        paramMap.put("orderStatusArr", orderStatusArr);
        paramMap.put("refundsPrice", refundsPrice);
        paramMap.put("statusName", statusName);
        try {
            //step2:修改订单状态
            this.iOrderService.updateOrderRefundsStatus(paramMap);
            return JsonUtil.returnJsonSuccess("操作订单状态成功!");
        } catch (Exception e) {
            return JsonUtil.returnJsonUnSuccess(CommonExceptionHandle.handleException(e));
        }
    }

    /**
     * 试吃订单交接单打印
     * @param orderIds
     * @param model
     * @return
     */
    @RequestMapping(value = "/printHandOverOrderComfirmed", method = RequestMethod.GET)
    public String printHandOverOrderComfirmed(@RequestParam(value = "orderIds", required = false) String orderIds,
                                              Model model) {
        //step1:封装请求参数
        try {
            //step2:获取订单列表对象
            List<OrderModel> orderList = this.iOrderService.selectHandOverOrdersComfirmed(orderIds);
            model.addAttribute("orderList", orderList);
            model.addAttribute("userName", this.getUserSeesion().getTrueName());
            String nowDate = DateUtils.DateToString(new Date(),
                DateUtils.FORMAT_yyyy_nian_M_yue_m_ri);
            model.addAttribute("nowDate", nowDate);
        } catch (Exception e) {
            return JsonUtil.returnJsonUnSuccess(CommonExceptionHandle.handleException(e));
        }
        return "print/OrderComfirmDeliveryReceitp";
    }

    /**
     * 今日达订单查询
     * @param orderModel
     * @return
     */
    @RequestMapping(value = "/selectTodayOrders", method = RequestMethod.POST)
    @ResponseBody
    public String selectTodayOrders(@ModelAttribute OrdersTodayModel orderModel) {
        //step1:获取请求参数
        PagingBean page = getInitPagingSortBean();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("OrdersTodayModel", orderModel);
        map.put("pagingBean", page);
        try {
            //step2:查询订单数据
            List<OrdersTodayModel> list = this.iOrderService.selectTodayOrders(map);
            Long count = this.iOrderService.selectTodayOrdersCount(map);
            //step3:返回订单数据
            return JsonUtil.writeObjectPageJSON(list, count);
        } catch (Exception e) {
            return JsonUtil.returnJsonUnSuccess(CommonExceptionHandle.handleException(e));
        }
    }

    /**
     * 重新发送邮件
     * @param json
     * @return
     */
    @RequestMapping(value = { "/sendOrderMail" }, method = { RequestMethod.GET })
    public @ResponseBody
    String initTopic() {
        //返回对象
        //step1:获取前一天4点前和4点后的订单信息
        Map<String, Object> orderMap = null;
        try {
            orderMap = this.iOrderService.statisticsOrderReport();
            String orderReportUrl = String.valueOf(orderMap.get("orderReportUrl"));
            logger.error("统计报表邮件链接地址为:" + orderReportUrl);
            if (StringUtils.isNotEmpty(orderReportUrl)) {
                String templateHtml = "<p>Dear all:</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MM统计报表已生成,请点击如下链接查看</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="
                                      + orderReportUrl + ">" + orderReportUrl + "</a></p>";
                //cc MAIL
                logger.error("统计订发送邮件!");
                String[] toMailArray = CommonConstants.EMAIL_TO_MAIL.split(",");
                logger.error("开始准备发送邮件!");
                Date nightBeforDate = DateUtils.getSomeDayDate(-1);
                String nightBeforDateString = DateUtils.date2StrDate(nightBeforDate);
                MimeMessage msg = javaMailSender.createMimeMessage();
                MimeMessageHelper helper;
                helper = new MimeMessageHelper(msg, true, "UTF-8");
                helper.setFrom(CommonConstants.EMAIL_FROM_ADDRESS); // 邮件发送地址,这里必须和xml里的邮件地址相同一致  
                helper.setTo(toMailArray); // 邮件接收地址  
                helper.setSubject(nightBeforDateString + "交易订单统计"); // 主题  
                helper.setText(templateHtml, true); // 邮件内容，注意加参数true，表示启用html格式  
                logger.error("发送邮件开始!");
                javaMailSender.send(msg);
                logger.error("发送邮件结束!");
                logger.error(nightBeforDateString + "交易订单统计:邮件发送成功!");
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("订单统计邮件发送错误!", e);
        }
        return JsonUtil.writeObjectJSON("邮件发送成功!");
    }
}
